package org.zachary.prosocialbehaviorservice.infrastructure.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.ActivityItem;

import java.util.List;

public interface SpringDataActivityItemRepository  extends JpaRepository<ActivityItem, Integer> {
    @Query("SELECT a FROM ActivityItem a WHERE a.id IN :ids")
    List<ActivityItem> findByIdIn(@Param("ids") List<Integer> ids);
    @Modifying
    @Query("UPDATE ActivityItem ai SET ai.number = ai.number - 1 WHERE ai.id = :id AND ai.number > 0")
    void decrementNumberById(@Param("id") Integer id);
}
